package MapStruct知识;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Data
@AllArgsConstructor
class Student {
    private String username1;
    private Integer age1;
}

@Data
@AllArgsConstructor
class StudentDTO {
    private String username2;
    private Integer age2;
}

@Mapper
interface StudentMapper {
    StudentMapper INSTANCE = Mappers.getMapper(StudentMapper.class);
    @Mapping(source = "username1", target = "username2")
    @Mapping(source = "age1", target = "age2")
    StudentDTO toStudentDTO(Student student);
}

public class SimpleDemo {
    public static void main(String[] args) {
        Student student = new Student("码农", 20);
        StudentDTO studentDTO = StudentMapper.INSTANCE.toStudentDTO(student);
        System.out.println(studentDTO);
    }
}
